package cn.edu.xjtu.competiton.lccp;

import cn.edu.xjtu.Util.TreeNode.TreeNode;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

/**
 * @author Hydrion-QLz
 * @date 2022-04-16 15:32
 * @description
 */
public class Third1 {
    public static void main(String[] args) {
        Third1 solution = new Third1();
        System.out.println(solution);
    }

    ArrayList<Integer> list = new ArrayList<>();
    Map<Integer, Integer> map = new HashMap<>();

    public int getNumber(TreeNode root, int[][] ops) {
        inOrder(root);
        int[] color = new int[list.size()];
        int ans = 0;
        for (int i = 0; i < ops.length; i++) {
            int left = map.get(ops[i][1]);
            int right = map.get(ops[i][2]);
            int type = ops[i][0];
            for (int j = left; j <= right; j++) {
                color[j] = type;
            }
        }
        for (int i = 0; i < color.length; i++) {
            if (color[i] == 1) {
                ans++;
            }
        }
        return ans;
    }

    private void inOrder(TreeNode root) {
        if (root == null) {
            return;
        }
        inOrder(root.left);
        list.add(root.val);
        map.put(root.val, list.size() - 1);
        inOrder(root.right);
    }
}
